<!DOCTYPE html>
<html lang="en" class="page-fill" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>huoyun | 物流管理系统 - 登录</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="ok-admin v2.0,ok-admin网站后台模版,后台模版下载,后台管理系统模版,HTML后台模版下载">
    <meta name="description" content="ok-admin v2.0，顾名思义，很赞的后台模版，它是一款基于Layui框架的轻量级扁平化且完全免费开源的网站后台管理系统模板，适合中小型CMS后台系统。">
    <link rel="shortcut icon" th:href="@{/images/favicon.ico}" type="image/x-icon"/>
    <link rel="stylesheet" th:href="@{/css/oksub.css}"/>
</head>
<body class="page-fill">
    <div class="page-fill" id="login">
        <form class="layui-form">
            <div class="login_face"><img th:src="@{/images/logo.png}"></div>
            <div class="layui-form-item input-item">
                <label for="username">用户名</label>
                <input type="text" lay-verify="required" name="username" placeholder="请输入账号" autocomplete="off" id="username" class="layui-input">
            </div>
            <div class="layui-form-item input-item">
                <label for="password">密码</label>
                <input type="password" lay-verify="required|password" name="password" placeholder="请输入密码" autocomplete="off" id="password" class="layui-input">
            </div>
            <!--验证码功能尚不完善，有待提高 -->
           <!-- <div class="layui-form-item input-item">
                <label for="phone">手机号</label>
                <input type="text" lay-verify="phone" name="phone" placeholder="请输入手机号" autocomplete="off" id="phone" class="layui-input">
            </div>
            <input class="layui-btn"  type="button" id="verify" value="获取验证码"/>
            <input type="text" lay-verify="required" name="captcha" placeholder="请输入验证码" autocomplete="off" id="" maxlength="6" class="layui-input">-->

            <!-- <div class="layui-form-item input-item captcha-box">
                 <label for="captcha">验证码</label>
                 <input type="text" lay-verify="required|captcha" name="captcha" placeholder="请输入验证码" autocomplete="off" id="captcha" maxlength="4" class="layui-input">
                 <div class="img ok-none-select" id="captchaImg"></div>
             </div>-->
            <div class="layui-form-item">
                <button class="layui-btn layui-block" lay-filter="login" lay-submit="">登录</button>
            </div>
            <div class="login-link">
                <a th:href="@{register.html}">注册</a>
                <a th:href="@{forget.html}">忘记密码?</a>
            </div>
        </form>
    </div>
    <!--js逻辑-->
    <script th:src="@{/lib/layui/layui.js}"></script>
    <script>
        layui.use(["form", "okGVerify", "okUtils", "okLayer"], function () {
            var form = layui.form;
             $ = layui.jquery;
            var okGVerify = layui.okGVerify;
            var okUtils = layui.okUtils;
            var okLayer = layui.okLayer;


            /**
             * 初始化验证码
             */
            // var verifyCode = new okGVerify("#captchaImg");

            /**
             * 数据校验
             */
            form.verify({
                password: [/^[\S]{6,12}$/, "密码必须6到12位，且不能出现空格"],
                captcha: function (val) {
                    if (verifyCode.validate(val) != "true") {
                        return verifyCode.validate(val)
                    }
                }
            });


            var codeTime = 10;

            $('#verify').click(function () {

                    sendSms();

            })
            function sendSms() {
            //发送ajax请求获取验证码

                $.post("/api/verify/getCode",{
                    phone:$("#phone").val()  //将需要删除的员工编号作为参数传入
                },function(data){
                    if (data.code == 200) {
                        alert("获取验证码成功");
                        //startTime(obj);
                    } else {

                        layer.msg(data.msg,{icon:2});
                    }

                })


            }
            //开启验证码倒计时，并且在时间内不能重复点击
            function startTime(obj) {
                var ins = setInterval(function () {
                    if(codeTime==0){
                        $(obj).attr("disabled",false);
                        $(obj).val("获取验证码");
                        codeTime=10;
                        clearInterval(ins);
                    }else{
                        $(obj).attr("disabled",true);
                        $(obj).val("重新发送("+codeTime+")秒");
                        codeTime--;
                    }
                },1000);
            }





            /**
             * 表单提交
             */
            form.on("submit(login)", function (data) {
    	    	var login_btn = $(this);
    	    	login_btn.text("登录中...").attr("disabled","disabled").addClass("layui-disabled");
    	    	
    	        //登录操作
    	        var params = data.field;
    	        //方式一：
    	        //ajax
    	        $.post("[[@{/api/staff/loginCheck}]]",params,function(d){
    	        	
    	        	console.info(d.code)
    	        	
    	        	if (d.code == 200) {
    	        		//成功
    	        		console.info("成功")
    	        		location.href = "index";
    	        	} else {
    	        		//失败
    	        		layer.msg(d.msg,{icon:2});
    	        		login_btn.text("登录").removeAttr("disabled").removeClass("layui-disabled");
    	        	}
    	        })
    	        //方式二：
    	        //location.href = "/sys?op=login"; 在sys servlet中进行重定向到主页
    	        return false;
            });

            /**
             * 表单input组件单击时
             */
            $("#login .input-item .layui-input").click(function (e) {
                e.stopPropagation();
                $(this).addClass("layui-input-focus").find(".layui-input").focus();
            });

            /**
             * 表单input组件获取焦点时
             */
            $("#login .layui-form-item .layui-input").focus(function () {
                $(this).parent().addClass("layui-input-focus");
            });

            /**
             * 表单input组件失去焦点时
             */
            $("#login .layui-form-item .layui-input").blur(function () {
                $(this).parent().removeClass("layui-input-focus");
                if ($(this).val() != "") {
                    $(this).parent().addClass("layui-input-active");
                } else {
                    $(this).parent().removeClass("layui-input-active");
                }
            })
        });




    </script>
</body>
</html>
